package com.unknowpupil.design.proxy.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description: <p>
 *
 * </p>
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2020/4/27 17:47
 * @Classname: StarHandler
 * @Version: 1.0
 */
public class StarHandler implements InvocationHandler {


    Star realStar;

    public StarHandler(Star realStar) {
        this.realStar = realStar;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object obj = null;
        System.out.println("进入统一处理器");
        System.out.println("代理操作 ProxyStar.confer ProxyStar.signContract ProxyStar.bookTicket");
        // 激活你调用的方法
        if(method.getName().equals("sing")){
            System.out.println("真实操作");
            obj = method.invoke(realStar,args);
        }
        System.out.println("代理操作 ProxyStar.collectMoney");

        return obj;
    }
}
